<template>
  <div class="picshare_container">
    <div id="slider" class="mui-slider">
      <div class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <a :class="['mui-control-item', item.id === 0 ? 'mui-active': '']"
            v-for="item in cates" :key="item.id"
            @tap="getPhotoBycateid(item.id)">
            {{ item.title }}
          </a>
        </div>
      </div>
    </div>

    <ul class="plist">
      <li v-for="item in imgList" :key="item.id"
        @click="jumpToInfo(item.id)">
        <img v-lazy="item.img_url">
        <div class="info">
          <h3 class="title">{{ item.title }}</h3>
          <div class="content">{{ item.zhaiyao }}</div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
  import mui from '../../../../lib/mui/js/mui'

  export default {
    name: 'picshare',
    mounted() {
      mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.005
      })
    },
    data() {
      return {
        cates: [],
        imgList: []
      }
    },
    created() {
      this.$store.dispatch('getImgCategory').then(res => {
        if(res.data.code === 200) {
          res.data.list.unshift({title: '全部', id: 0})
          this.cates = res.data.list
        }
      })
      this.getPhotoBycateid(0)
    },
    methods: {
      getPhotoBycateid(id) {
        this.$store.dispatch('getImages', id).then(res => {
          if(res.data.code === 200) {
            res.data.list.forEach(item => {
              item.img_url = item.img_url.replace(/..\/../, '/static')
            });
            this.imgList = res.data.list
          }
        })
      },
      jumpToInfo(id) {
        this.$router.push({
          path: '/home/picinfo',
          params: { id }, 
          name: 'picinfo' 
        })
      }
    }
  }
</script>

<style lang="less" scoped>
  * {
    touch-action: pan-y;
  }

  .plist {
    list-style: none;
    padding: 10px;
    padding-bottom: 0;
    margin: 0;
    li {
      margin-bottom: 10px;
      box-shadow: 0 0 9px #999;
      position: relative;
      display: flex;
      img {
        width: 100%;
      }
      .info {
        width: 100%;
        color: #fff;
        background-color: rgba(0,0,0,.4);
        position: absolute;
        bottom: 0;
        min-height: 60px;
        max-height: 84px;
        .title {
          font-size: 14px;
        }
        .content {
          font-size: 13px;
        }
      }
    }
  }
</style>
